package set;

public class Student implements Comparable<Student>{
    @Override
    public int compareTo(Student o){
        System.out.println(this.age+"...."+o.age);
//        this.age-o.age 正序
//        o.age-this.age 降序
//        根据年龄做主要排序，姓名做次要排序，降序排序
        int ageResult=o.age-this.age;
        int result=ageResult==0?o.name.compareTo(this.name):ageResult;
        return result;
//        return this.age-o.age;
    }
    private String name;
    private int age;
    public Student(){

    }
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
